import {Component, Input, OnInit, TemplateRef} from '@angular/core';
import {BsModalRef, BsModalService} from 'ngx-bootstrap';
import {WmsPurchaseOrderSelfCondition} from '../../wms-purchase-order-self.type';
import {Services} from '../../../../../frame/module/services';

@Component({
  selector: 'app-wms-order-info',
  templateUrl: './wms-order-info.component.html',
  styleUrls: ['./wms-order-info.component.css']
})
export class WmsOrderInfoComponent implements OnInit {

    modalRef: BsModalRef;
    searchFlag = false;
    orderInfo = {
        info: {},
        orderLines: []
    }

    @Input()
    orderId;

    wmsCondition = new WmsPurchaseOrderSelfCondition();
    // 选中的行
    selectedRowMap = new Map();
    // 判断是否选中
    isSelected = (id) => {
        return this.selectedRowMap.get(id) ? true : false;
    }
    // 处理行选中
    dealSelected = (item) => {
        console.log('点击row');
        if (this.isSelected(item.id)) {
            // 删除此行
            this.selectedRowMap.delete(item.id);
        } else {
            this.selectedRowMap.set(item.id, '1');
        }
    }



    constructor(private modalService: BsModalService) {
    }


    openModal(template: TemplateRef<any>) {
        // 查询订单数据
        const orderId = this.orderId;
        this.modalRef = this.modalService.show(template, Object.assign({}, { class: 'gray modal-lg' } ));
        this.wmsCondition.uuid = orderId;
        Services.wmsPurchaseOrderSelf.info( this.wmsCondition).subscribe(data => {
            const { domain }  = data;
            this.orderInfo.orderLines = domain.wmsPurchaseOrderLines;
            this.orderInfo.info = domain;
            console.log(data);
        });
    }

    ngOnInit() {
    }

}
